<?php

/**
 * Генераци�? �?�?ылки дл�? sfPropelPager'a
 *
 * @param sfContext $sf_context
 * @param int $pageNumber
 * @return string
 */
function urlToPage(sfContext $sf_context, $pageNumber, array $restriction = array(),$page_param = 'page') {
  $page_routing = $sf_context->getRouting();
  $current_page_url = $page_routing->getCurrentInternalUri();
  $tmp = parse_url($current_page_url);
  if (isset($tmp['query']))
  {
    parse_str($tmp['query'], $tmp2);
    unset($tmp2[$page_param]);
    $path_split = split("/",$tmp["path"]);
  }
  else
  {
      $tmp2 = array();
  }
  $tmp3 = array();
  if (isset($extra)) {$tmp2 = array_merge($tmp2,$extra);}
  foreach($tmp2 as $key=>$val) {@$tmp3[]=$key."=".urlencode($val);}
  return url_for($current_page_url = $tmp["path"]."?".join("&", $tmp3)."&$page_param=".$pageNumber.(count($restriction) ? '&'.http_build_query($restriction) : ''));
  
}

/**
 * У�?тановка пробелом в длинные �?лова
 *
 * @param string $string
 * @param int $chars
 * @return string
 */
function word_split($text, $symbolsQuantity = 10)
{
  $regExp = '/(\<.*\>)+/U';
  preg_match_all($regExp, $text, $matches);
  $text = preg_replace($regExp, '%tag%', $text);

  $regExp = '/([^ %tag%]){' . $symbolsQuantity . '}/';
  $replacement = '\0 ';
  $text = preg_replace($regExp, $replacement, $text);

  foreach ($matches[0] as $match)
  {
    $text = preg_replace('(%tag%)', $match, $text, 1);
  }
  return $text;
}

?>